home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 85 / CD Temático 40 Febrero 2004.iso / DOS / testdisk / src / ext2fs / ext2fs.h < prev    next >
Encoding:
C/C++ Source or Header  |  2003-10-04  |  28.6 KB  |  998 lines

  1. /*
  2.  * ext2fs.h --- ext2fs
  3.  * 
  4.  * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
  5.  *
  6.  * %Begin-Header%
  7.  * This file may be redistributed under the terms of the GNU Public
  8.  * License.
  9.  * %End-Header%
  10.  */
  11.  
  12. #ifndef _EXT2FS_EXT2FS_H
  13. #define _EXT2FS_EXT2FS_H
  14.  
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18.  
  19. /*
  20.  * Non-GNU C compilers won't necessarily understand inline
  21.  */
  22. #if (!defined(__GNUC__) && !defined(__WATCOMC__))
  23. #define NO_INLINE_FUNCS
  24. #endif
  25.  
  26. /*
  27.  * Build in support for byte-swapping filesystems if we the feature
  28.  * has been configured or if we're being built on a CPU architecture
  29.  * with a non-native byte order.
  30.  */
  31. #if defined(ENABLE_SWAPFS) || defined(WORDS_BIGENDIAN)
  32. #define EXT2FS_ENABLE_SWAPFS
  33. #endif
  34.  
  35. /*
  36.  * Where the master copy of the superblock is located, and how big
  37.  * superblocks are supposed to be.  We define SUPERBLOCK_SIZE because
  38.  * the size of the superblock structure is not necessarily trustworthy
  39.  * (some versions have the padding set up so that the superblock is
  40.  * 1032 bytes long).
  41.  */
  42. #define SUPERBLOCK_OFFSET    1024
  43. #define SUPERBLOCK_SIZE     1024
  44.  
  45. /*
  46.  * The last ext2fs revision level that this version of the library is
  47.  * able to support.
  48.  */
  49. #define EXT2_LIB_CURRENT_REV    EXT2_DYNAMIC_REV
  50.  
  51. #ifdef HAVE_SYS_TYPES_H
  52. #include <sys/types.h>
  53. #endif
  54.  
  55. #include <stdlib.h>
  56.  
  57. #if EXT2_FLAT_INCLUDES
  58. #include "e2_types.h"
  59. #else
  60. #include <ext2fs/ext2_types.h>
  61. #endif /* EXT2_FLAT_INCLUDES */
  62.  
  63. typedef __u32        ext2_ino_t;
  64. typedef __u32        blk_t;
  65. typedef __u32        dgrp_t;
  66. typedef __u32        ext2_off_t;
  67. typedef __s64        e2_blkcnt_t;
  68.  
  69. #if EXT2_FLAT_INCLUDES
  70. #include "com_err.h"
  71. #include "ext2_io.h"
  72. #include "ext2_err.h"
  73. #else
  74. #include <et/com_err.h>
  75. #include <ext2fs/ext2_io.h>
  76. #include <ext2fs/ext2_err.h>
  77. #endif
  78.  
  79. /*
  80.  * Portability help for Microsoft Visual C++
  81.  */
  82. #ifdef _MSC_VER
  83. #define EXT2_QSORT_TYPE int __cdecl
  84. #else
  85. #define EXT2_QSORT_TYPE int
  86. #endif
  87.  
  88. typedef struct struct_ext2_filsys *ext2_filsys;
  89.  
  90. struct ext2fs_struct_generic_bitmap {
  91.     errcode_t    magic;
  92.     ext2_filsys     fs;
  93.     __u32        start, end;
  94.     __u32        real_end;
  95.     char    *    description;
  96.     char    *    bitmap;
  97.     errcode_t    base_error_code;
  98.     __u32        reserved[7];
  99. };
  100.  
  101. #define EXT2FS_MARK_ERROR     0
  102. #define EXT2FS_UNMARK_ERROR     1
  103. #define EXT2FS_TEST_ERROR    2
  104.  
  105. typedef struct ext2fs_struct_generic_bitmap *ext2fs_generic_bitmap;
  106. typedef struct ext2fs_struct_generic_bitmap *ext2fs_inode_bitmap;
  107. typedef struct ext2fs_struct_generic_bitmap *ext2fs_block_bitmap;
  108.  
  109. #ifdef EXT2_DYNAMIC_REV
  110. #define EXT2_FIRST_INODE(s)    EXT2_FIRST_INO(s)
  111. #else
  112. #define EXT2_FIRST_INODE(s)    EXT2_FIRST_INO
  113. #define EXT2_INODE_SIZE(s)    sizeof(struct ext2_inode)
  114. #endif
  115.  
  116. /*
  117.  * badblocks list definitions
  118.  */
  119.  
  120. typedef struct ext2_struct_badblocks_list *ext2_badblocks_list;
  121. typedef struct ext2_struct_badblocks_iterate *ext2_badblocks_iterate;
  122.  
  123. /* old */
  124. typedef struct ext2_struct_badblocks_list *badblocks_list;
  125. typedef struct ext2_struct_badblocks_iterate *badblocks_iterate;
  126.  
  127. #define BADBLOCKS_FLAG_DIRTY    1
  128.  
  129. /*
  130.  * ext2_dblist structure and abstractions (see dblist.c)
  131.  */
  132. struct ext2_db_entry {
  133.     ext2_ino_t    ino;
  134.     blk_t    blk;
  135.     int    blockcnt;
  136. };
  137.  
  138. typedef struct ext2_struct_dblist *ext2_dblist;
  139.  
  140. #define DBLIST_ABORT    1
  141.  
  142. /*
  143.  * ext2_fileio definitions
  144.  */
  145.  
  146. #define EXT2_FILE_WRITE        0x0001
  147. #define EXT2_FILE_CREATE    0x0002
  148.  
  149. #define EXT2_FILE_MASK        0x00FF
  150.  
  151. #define EXT2_FILE_BUF_DIRTY    0x4000
  152. #define EXT2_FILE_BUF_VALID    0x2000
  153.  
  154. typedef struct ext2_file *ext2_file_t;
  155.  
  156. #define EXT2_SEEK_SET    0
  157. #define EXT2_SEEK_CUR    1
  158. #define EXT2_SEEK_END    2
  159.  
  160. /*
  161.  * Flags for the ext2_filsys structure and for ext2fs_open()
  162.  */
  163. #define EXT2_FLAG_RW            0x01
  164. #define EXT2_FLAG_CHANGED        0x02
  165. #define EXT2_FLAG_DIRTY            0x04
  166. #define EXT2_FLAG_VALID            0x08
  167. #define EXT2_FLAG_IB_DIRTY        0x10
  168. #define EXT2_FLAG_BB_DIRTY        0x20
  169. #define EXT2_FLAG_SWAP_BYTES        0x40
  170. #define EXT2_FLAG_SWAP_BYTES_READ    0x80
  171. #define EXT2_FLAG_SWAP_BYTES_WRITE    0x100
  172. #define EXT2_FLAG_MASTER_SB_ONLY    0x200
  173. #define EXT2_FLAG_FORCE            0x400
  174. #define EXT2_FLAG_SUPER_ONLY        0x800
  175. #define EXT2_FLAG_JOURNAL_DEV_OK    0x1000
  176. #define EXT2_FLAG_IMAGE_FILE        0x2000
  177.  
  178. /*
  179.  * Special flag in the ext2 inode i_flag field that means that this is
  180.  * a new inode.  (So that ext2_write_inode() can clear extra fields.)
  181.  */
  182. #define EXT2_NEW_INODE_FL    0x80000000
  183.  
  184. /*
  185.  * Flags for mkjournal
  186.  *
  187.  * EXT2_MKJOURNAL_V1_SUPER    Make a (deprecated) V1 journal superblock
  188.  */
  189. #define EXT2_MKJOURNAL_V1_SUPER    0x0000001
  190.  
  191. struct struct_ext2_filsys {
  192.     errcode_t            magic;
  193.     io_channel            io;
  194.     int                flags;
  195.     char *                device_name;
  196.     struct ext2_super_block    *     super;
  197.     int                blocksize;
  198.     int                fragsize;
  199.     dgrp_t                group_desc_count;
  200.     unsigned long            desc_blocks;
  201.     struct ext2_group_desc *    group_desc;
  202.     int                inode_blocks_per_group;
  203.     ext2fs_inode_bitmap        inode_map;
  204.     ext2fs_block_bitmap        block_map;
  205.     errcode_t (*get_blocks)(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
  206.     errcode_t (*check_directory)(ext2_filsys fs, ext2_ino_t ino);
  207.     errcode_t (*write_bitmaps)(ext2_filsys fs);
  208.     errcode_t (*read_inode)(ext2_filsys fs, ext2_ino_t ino,
  209.                 struct ext2_inode *inode);
  210.     errcode_t (*write_inode)(ext2_filsys fs, ext2_ino_t ino,
  211.                 struct ext2_inode *inode);
  212.     badblocks_list            badblocks;
  213.     ext2_dblist            dblist;
  214.     __u32                stride;    /* for mke2fs */
  215.     struct ext2_super_block *    orig_super;
  216.     struct ext2_image_hdr *        image_header;
  217.     __u32                umask;
  218.     /*
  219.      * Reserved for future expansion
  220.      */
  221.     __u32                reserved[8];
  222.  
  223.     /*
  224.      * Reserved for the use of the calling application.
  225.      */
  226.     void *                priv_data;
  227.  
  228.     /*
  229.      * Inode cache
  230.      */
  231.     struct ext2_inode_cache        *icache;
  232. };
  233.  
  234. #if EXT2_FLAT_INCLUDES
  235. #include "e2_bitops.h"
  236. #else
  237. #include <ext2fs/bitops.h>
  238. #endif
  239.  
  240. /*
  241.  * Return flags for the block iterator functions
  242.  */
  243. #define BLOCK_CHANGED    1
  244. #define BLOCK_ABORT    2
  245. #define BLOCK_ERROR    4
  246.  
  247. /*
  248.  * Block interate flags
  249.  *
  250.  * BLOCK_FLAG_APPEND, or BLOCK_FLAG_HOLE, indicates that the interator
  251.  * function should be called on blocks where the block number is zero.
  252.  * This is used by ext2fs_expand_dir() to be able to add a new block
  253.  * to an inode.  It can also be used for programs that want to be able
  254.  * to deal with files that contain "holes".
  255.  * 
  256.  * BLOCK_FLAG_TRAVERSE indicates that the iterator function for the
  257.  * indirect, doubly indirect, etc. blocks should be called after all
  258.  * of the blocks containined in the indirect blocks are processed.
  259.  * This is useful if you are going to be deallocating blocks from an
  260.  * inode.
  261.  *
  262.  * BLOCK_FLAG_DATA_ONLY indicates that the iterator function should be
  263.  * called for data blocks only.
  264.  *
  265.  * BLOCK_FLAG_NO_LARGE is for internal use only.  It informs
  266.  * ext2fs_block_iterate2 that large files won't be accepted.
  267.  */
  268. #define BLOCK_FLAG_APPEND    1
  269. #define BLOCK_FLAG_HOLE        1
  270. #define BLOCK_FLAG_DEPTH_TRAVERSE    2
  271. #define BLOCK_FLAG_DATA_ONLY    4
  272.  
  273. #define BLOCK_FLAG_NO_LARGE    0x1000
  274.  
  275. /*
  276.  * Magic "block count" return values for the block iterator function.
  277.  */
  278. #define BLOCK_COUNT_IND        (-1)
  279. #define BLOCK_COUNT_DIND    (-2)
  280. #define BLOCK_COUNT_TIND    (-3)
  281. #define BLOCK_COUNT_TRANSLATOR    (-4)
  282.  
  283. #if 0
  284. /*
  285.  * Flags for ext2fs_move_blocks
  286.  */
  287. #define EXT2_BMOVE_GET_DBLIST    0x0001    
  288. #define EXT2_BMOVE_DEBUG    0x0002
  289. #endif
  290.  
  291. /*
  292.  * Return flags for the directory iterator functions
  293.  */
  294. #define DIRENT_CHANGED    1
  295. #define DIRENT_ABORT    2
  296. #define DIRENT_ERROR    3
  297.  
  298. /*
  299.  * Directory iterator flags
  300.  */
  301.  
  302. #define DIRENT_FLAG_INCLUDE_EMPTY    1
  303. #define DIRENT_FLAG_INCLUDE_REMOVED    2
  304.  
  305. #define DIRENT_DOT_FILE        1
  306. #define DIRENT_DOT_DOT_FILE    2
  307. #define DIRENT_OTHER_FILE    3
  308. #define DIRENT_DELETED_FILE    4
  309.  
  310. /*
  311.  * Inode scan definitions
  312.  */
  313. typedef struct ext2_struct_inode_scan *ext2_inode_scan;
  314.  
  315. /*
  316.  * ext2fs_scan flags
  317.  */
  318. #define EXT2_SF_CHK_BADBLOCKS    0x0001
  319. #define EXT2_SF_BAD_INODE_BLK    0x0002
  320. #define EXT2_SF_BAD_EXTRA_BYTES    0x0004
  321. #define EXT2_SF_SKIP_MISSING_ITABLE    0x0008
  322.  
  323. /*
  324.  * ext2fs_check_if_mounted flags
  325.  */
  326. #define EXT2_MF_MOUNTED        1
  327. #define EXT2_MF_ISROOT        2
  328. #define EXT2_MF_READONLY    4
  329. #define EXT2_MF_SWAP        8
  330.  
  331. /*
  332.  * Ext2/linux mode flags.  We define them here so that we don't need
  333.  * to depend on the OS's sys/stat.h, since we may be compiling on a
  334.  * non-Linux system.
  335.  */
  336. #define LINUX_S_IFMT  00170000
  337. #define LINUX_S_IFSOCK 0140000
  338. #define LINUX_S_IFLNK     0120000
  339. #define LINUX_S_IFREG  0100000
  340. #define LINUX_S_IFBLK  0060000
  341. #define LINUX_S_IFDIR  0040000
  342. #define LINUX_S_IFCHR  0020000
  343. #define LINUX_S_IFIFO  0010000
  344. #define LINUX_S_ISUID  0004000
  345. #define LINUX_S_ISGID  0002000
  346. #define LINUX_S_ISVTX  0001000
  347.  
  348. #define LINUX_S_IRWXU 00700
  349. #define LINUX_S_IRUSR 00400
  350. #define LINUX_S_IWUSR 00200
  351. #define LINUX_S_IXUSR 00100
  352.  
  353. #define LINUX_S_IRWXG 00070
  354. #define LINUX_S_IRGRP 00040
  355. #define LINUX_S_IWGRP 00020
  356. #define LINUX_S_IXGRP 00010
  357.  
  358. #define LINUX_S_IRWXO 00007
  359. #define LINUX_S_IROTH 00004
  360. #define LINUX_S_IWOTH 00002
  361. #define LINUX_S_IXOTH 00001
  362.  
  363. #define LINUX_S_ISLNK(m)    (((m) & LINUX_S_IFMT) == LINUX_S_IFLNK)
  364. #define LINUX_S_ISREG(m)    (((m) & LINUX_S_IFMT) == LINUX_S_IFREG)
  365. #define LINUX_S_ISDIR(m)    (((m) & LINUX_S_IFMT) == LINUX_S_IFDIR)
  366. #define LINUX_S_ISCHR(m)    (((m) & LINUX_S_IFMT) == LINUX_S_IFCHR)
  367. #define LINUX_S_ISBLK(m)    (((m) & LINUX_S_IFMT) == LINUX_S_IFBLK)
  368. #define LINUX_S_ISFIFO(m)    (((m) & LINUX_S_IFMT) == LINUX_S_IFIFO)
  369. #define LINUX_S_ISSOCK(m)    (((m) & LINUX_S_IFMT) == LINUX_S_IFSOCK)
  370.  
  371. /*
  372.  * ext2_icount_t abstraction
  373.  */
  374. #define EXT2_ICOUNT_OPT_INCREMENT    0x01
  375.  
  376. typedef struct ext2_icount *ext2_icount_t;
  377.  
  378. /*
  379.  * Flags for ext2fs_bmap
  380.  */
  381. #define BMAP_ALLOC    1
  382.  
  383. /*
  384.  * Flags for imager.c functions
  385.  */
  386. #define IMAGER_FLAG_INODEMAP    1
  387. #define IMAGER_FLAG_SPARSEWRITE    2
  388.  
  389. /*
  390.  * For checking structure magic numbers...
  391.  */
  392.  
  393. #define EXT2_CHECK_MAGIC(struct, code) \
  394.       if ((struct)->magic != (code)) return (code)
  395.  
  396.  
  397. /*
  398.  * For ext2 compression support
  399.  */
  400. #define EXT2FS_COMPRESSED_BLKADDR ((blk_t) 0xffffffff)
  401. #define HOLE_BLKADDR(_b) ((_b) == 0 || (_b) == EXT2FS_COMPRESSED_BLKADDR)
  402.  
  403. /*
  404.  * Features supported by this version of the library
  405.  */
  406. #define EXT2_LIB_FEATURE_COMPAT_SUPP    (EXT2_FEATURE_COMPAT_DIR_PREALLOC|\
  407.                      EXT2_FEATURE_COMPAT_IMAGIC_INODES|\
  408.                      EXT3_FEATURE_COMPAT_HAS_JOURNAL|\
  409.                      EXT2_FEATURE_COMPAT_EXT_ATTR)
  410.  
  411. /* This #ifdef is temporary until compression is fully supported */
  412. #ifdef ENABLE_COMPRESSION
  413. #ifndef I_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL
  414. /* If the below warning bugs you, then have
  415.    `CPPFLAGS=-DI_KNOW_THAT_COMPRESSION_IS_EXPERIMENTAL' in your
  416.    environment at configure time. */
  417.  #warning "Compression support is experimental"
  418. #endif
  419. #define EXT2_LIB_FEATURE_INCOMPAT_SUPP    (EXT2_FEATURE_INCOMPAT_FILETYPE|\
  420.                      EXT2_FEATURE_INCOMPAT_COMPRESSION|\
  421.                      EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
  422.                      EXT3_FEATURE_INCOMPAT_RECOVER)
  423. #else
  424. #define EXT2_LIB_FEATURE_INCOMPAT_SUPP    (EXT2_FEATURE_INCOMPAT_FILETYPE|\
  425.                      EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
  426.                      EXT3_FEATURE_INCOMPAT_RECOVER)
  427. #endif
  428. #define EXT2_LIB_FEATURE_RO_COMPAT_SUPP    (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\
  429.                      EXT2_FEATURE_RO_COMPAT_LARGE_FILE)
  430. /*
  431.  * function prototypes
  432.  */
  433.  
  434. /* alloc.c */
  435. extern errcode_t ext2fs_new_inode(ext2_filsys fs, ext2_ino_t dir, int mode,
  436.                   ext2fs_inode_bitmap map, ext2_ino_t *ret);
  437. extern errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal,
  438.                   ext2fs_block_bitmap map, blk_t *ret);
  439. extern errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start,
  440.                     blk_t finish, int num,
  441.                     ext2fs_block_bitmap map,
  442.                     blk_t *ret);
  443. extern errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal,
  444.                     char *block_buf, blk_t *ret);
  445.  
  446. /* alloc_stats.c */
  447. void ext2fs_inode_alloc_stats(ext2_filsys fs, ext2_ino_t ino, int inuse);
  448. void ext2fs_inode_alloc_stats2(ext2_filsys fs, ext2_ino_t ino,
  449.                    int inuse, int isdir);
  450. void ext2fs_block_alloc_stats(ext2_filsys fs, blk_t blk, int inuse);
  451.  
  452. /* alloc_tables.c */
  453. extern errcode_t ext2fs_allocate_tables(ext2_filsys fs);
  454. extern errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
  455.                          ext2fs_block_bitmap bmap);
  456.  
  457. /* badblocks.c */
  458. extern errcode_t ext2fs_badblocks_list_create(ext2_badblocks_list *ret,
  459.                         int size);
  460. extern errcode_t ext2fs_badblocks_list_add(ext2_badblocks_list bb,
  461.                        blk_t blk);
  462. extern int ext2fs_badblocks_list_test(ext2_badblocks_list bb,
  463.                     blk_t blk);
  464. extern errcode_t
  465.     ext2fs_badblocks_list_iterate_begin(ext2_badblocks_list bb,
  466.                         ext2_badblocks_iterate *ret);
  467. extern int ext2fs_badblocks_list_iterate(ext2_badblocks_iterate iter,
  468.                      blk_t *blk);
  469. extern void ext2fs_badblocks_list_iterate_end(ext2_badblocks_iterate iter);
  470. extern errcode_t ext2fs_badblocks_copy(ext2_badblocks_list src,
  471.                        ext2_badblocks_list *dest);
  472. extern int ext2fs_badblocks_equal(ext2_badblocks_list bb1,
  473.                   ext2_badblocks_list bb2);
  474.  
  475. /* bb_compat */
  476. extern errcode_t badblocks_list_create(badblocks_list *ret, int size);
  477. extern errcode_t badblocks_list_add(badblocks_list bb, blk_t blk);
  478. extern int badblocks_list_test(badblocks_list bb, blk_t blk);
  479. extern errcode_t badblocks_list_iterate_begin(badblocks_list bb,
  480.                           badblocks_iterate *ret);
  481. extern int badblocks_list_iterate(badblocks_iterate iter, blk_t *blk);
  482. extern void badblocks_list_iterate_end(badblocks_iterate iter);
  483. extern void badblocks_list_free(badblocks_list bb);
  484.  
  485. /* bb_inode.c */
  486. extern errcode_t ext2fs_update_bb_inode(ext2_filsys fs,
  487.                     ext2_badblocks_list bb_list);
  488.  
  489. /* bitmaps.c */
  490. extern errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs);
  491. extern errcode_t ext2fs_write_block_bitmap (ext2_filsys fs);
  492. extern errcode_t ext2fs_read_inode_bitmap (ext2_filsys fs);
  493. extern errcode_t ext2fs_read_block_bitmap(ext2_filsys fs);
  494. extern errcode_t ext2fs_allocate_generic_bitmap(__u32 start,
  495.                         __u32 end,
  496.                         __u32 real_end,
  497.                         const char *descr,
  498.                         ext2fs_generic_bitmap *ret);
  499. extern errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs,
  500.                           const char *descr,
  501.                           ext2fs_block_bitmap *ret);
  502. extern errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs,
  503.                           const char *descr,
  504.                           ext2fs_inode_bitmap *ret);
  505. extern errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap,
  506.                            ext2_ino_t end, ext2_ino_t *oend);
  507. extern errcode_t ext2fs_fudge_block_bitmap_end(ext2fs_block_bitmap bitmap,
  508.                            blk_t end, blk_t *oend);
  509. extern void ext2fs_clear_inode_bitmap(ext2fs_inode_bitmap bitmap);
  510. extern void ext2fs_clear_block_bitmap(ext2fs_block_bitmap bitmap);
  511. extern errcode_t ext2fs_read_bitmaps(ext2_filsys fs);
  512. extern errcode_t ext2fs_write_bitmaps(ext2_filsys fs);
  513.  
  514. /* block.c */
  515. extern errcode_t ext2fs_block_iterate(ext2_filsys fs,
  516.                       ext2_ino_t    ino,
  517.                       int    flags,
  518.                       char *block_buf,
  519.                       int (*func)(ext2_filsys fs,
  520.                           blk_t    *blocknr,
  521.                           int    blockcnt,
  522.                           void    *priv_data),
  523.                       void *priv_data);
  524. errcode_t ext2fs_block_iterate2(ext2_filsys fs,
  525.                 ext2_ino_t    ino,
  526.                 int    flags,
  527.                 char *block_buf,
  528.                 int (*func)(ext2_filsys fs,
  529.                         blk_t    *blocknr,
  530.                         e2_blkcnt_t    blockcnt,
  531.                         blk_t    ref_blk,
  532.                         int        ref_offset,
  533.                         void    *priv_data),
  534.                 void *priv_data);
  535.  
  536. /* bmap.c */
  537. extern errcode_t ext2fs_bmap(ext2_filsys fs, ext2_ino_t ino,
  538.                  struct ext2_inode *inode, 
  539.                  char *block_buf, int bmap_flags,
  540.                  blk_t block, blk_t *phys_blk);
  541.  
  542.  
  543. #if 0
  544. /* bmove.c */
  545. extern errcode_t ext2fs_move_blocks(ext2_filsys fs,
  546.                     ext2fs_block_bitmap reserve,
  547.                     ext2fs_block_bitmap alloc_map,
  548.                     int flags);
  549. #endif
  550.  
  551. /* check_desc.c */
  552. extern errcode_t ext2fs_check_desc(ext2_filsys fs);
  553.  
  554. /* closefs.c */
  555. extern errcode_t ext2fs_close(ext2_filsys fs);
  556. extern errcode_t ext2fs_flush(ext2_filsys fs);
  557. extern int ext2fs_bg_has_super(ext2_filsys fs, int group_block);
  558. extern void ext2fs_update_dynamic_rev(ext2_filsys fs);
  559.  
  560. /* cmp_bitmaps.c */
  561. extern errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
  562.                          ext2fs_block_bitmap bm2);
  563. extern errcode_t ext2fs_compare_inode_bitmap(ext2fs_inode_bitmap bm1,
  564.                          ext2fs_inode_bitmap bm2);
  565.  
  566. /* dblist.c */
  567.  
  568. extern errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs);
  569. extern errcode_t ext2fs_init_dblist(ext2_filsys fs, ext2_dblist *ret_dblist);
  570. extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ext2_ino_t ino,
  571.                       blk_t blk, int blockcnt);
  572. extern errcode_t ext2fs_dblist_iterate(ext2_dblist dblist,
  573.     int (*func)(ext2_filsys fs, struct ext2_db_entry *db_info,
  574.             void    *priv_data),
  575.        void *priv_data);
  576. extern errcode_t ext2fs_set_dir_block(ext2_dblist dblist, ext2_ino_t ino,
  577.                       blk_t blk, int blockcnt);
  578. extern errcode_t ext2fs_copy_dblist(ext2_dblist src,
  579.                     ext2_dblist *dest);
  580. extern int ext2fs_dblist_count(ext2_dblist dblist);
  581.  
  582. /* dblist_dir.c */
  583. extern errcode_t
  584.     ext2fs_dblist_dir_iterate(ext2_dblist dblist,
  585.                   int    flags,
  586.                   char    *block_buf,
  587.                   int (*func)(ext2_ino_t    dir,
  588.                           int        entry,
  589.                           struct ext2_dir_entry *dirent,
  590.                           int    offset,
  591.                           int    blocksize,
  592.                           char    *buf,
  593.                           void    *priv_data),
  594.                   void *priv_data);
  595.  
  596. /* dirblock.c */
  597. extern errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block,
  598.                        void *buf);
  599. extern errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block,
  600.                     void *buf);
  601.  
  602. /* dir_iterate.c */
  603. extern errcode_t ext2fs_dir_iterate(ext2_filsys fs, 
  604.                   ext2_ino_t dir,
  605.                   int flags,
  606.                   char *block_buf,
  607.                   int (*func)(struct ext2_dir_entry *dirent,
  608.                       int    offset,
  609.                       int    blocksize,
  610.                       char    *buf,
  611.                       void    *priv_data),
  612.                   void *priv_data);
  613. extern errcode_t ext2fs_dir_iterate2(ext2_filsys fs, 
  614.                   ext2_ino_t dir,
  615.                   int flags,
  616.                   char *block_buf,
  617.                   int (*func)(ext2_ino_t    dir,
  618.                       int    entry,
  619.                       struct ext2_dir_entry *dirent,
  620.                       int    offset,
  621.                       int    blocksize,
  622.                       char    *buf,
  623.                       void    *priv_data),
  624.                   void *priv_data);
  625.  
  626. /* dupfs.c */
  627. extern errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest);
  628.  
  629. /* expanddir.c */
  630. extern errcode_t ext2fs_expand_dir(ext2_filsys fs, ext2_ino_t dir);
  631.  
  632. /* ext_attr.c */
  633. void ext2fs_swap_ext_attr(ext2_filsys fs, char *to, char *from);
  634. extern errcode_t ext2fs_read_ext_attr(ext2_filsys fs, blk_t block, void *buf);
  635. extern errcode_t ext2fs_write_ext_attr(ext2_filsys fs, blk_t block, void *buf); 
  636. /* fileio.c */
  637. extern errcode_t ext2fs_file_open(ext2_filsys fs, ext2_ino_t ino,
  638.                   int flags, ext2_file_t *ret);
  639. extern ext2_filsys ext2fs_file_get_fs(ext2_file_t file);
  640. extern errcode_t ext2fs_file_close(ext2_file_t file);
  641. extern errcode_t ext2fs_file_read(ext2_file_t file, void *buf,
  642.                   unsigned int wanted, unsigned int *got);
  643. extern errcode_t ext2fs_file_write(ext2_file_t file, void *buf,
  644.                    unsigned int nbytes, unsigned int *written);
  645. extern errcode_t ext2fs_file_lseek(ext2_file_t file, ext2_off_t offset,
  646.                    int whence, ext2_off_t *ret_pos);
  647. extern ext2_off_t ext2fs_file_get_size(ext2_file_t file);
  648. extern errcode_t ext2fs_file_set_size(ext2_file_t file, ext2_off_t size);
  649.  
  650. /* finddev.c */
  651. extern char *ext2fs_find_block_device(dev_t device);
  652.  
  653. /* flushb.c */
  654. extern errcode_t ext2fs_sync_device(int fd, int flushb);
  655.  
  656. /* freefs.c */
  657. extern void ext2fs_free(ext2_filsys fs);
  658. extern void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap);
  659. extern void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap);
  660. extern void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap);
  661. extern void ext2fs_free_dblist(ext2_dblist dblist);
  662. extern void ext2fs_badblocks_list_free(badblocks_list bb);
  663.  
  664. /* getsize.c */
  665. extern errcode_t ext2fs_get_device_size(const char *file, int blocksize,
  666.                     blk_t *retblocks);
  667.  
  668. /* imager.c */
  669. extern errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags);
  670. extern errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd, int flags);
  671. extern errcode_t ext2fs_image_super_write(ext2_filsys fs, int fd, int flags);
  672. extern errcode_t ext2fs_image_super_read(ext2_filsys fs, int fd, int flags);
  673. extern errcode_t ext2fs_image_bitmap_write(ext2_filsys fs, int fd, int flags);
  674. extern errcode_t ext2fs_image_bitmap_read(ext2_filsys fs, int fd, int flags);
  675.  
  676. /* initialize.c */
  677. extern errcode_t ext2fs_initialize(const char *name, int flags,
  678.                    struct ext2_super_block *param,
  679.                    io_manager manager, ext2_filsys *ret_fs);
  680.  
  681. /* inode.c */
  682. extern errcode_t ext2fs_flush_icache(ext2_filsys fs);
  683. extern errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks,
  684.                   ext2_inode_scan *ret_scan);
  685. extern void ext2fs_close_inode_scan(ext2_inode_scan scan);
  686. extern errcode_t ext2fs_get_next_inode(ext2_inode_scan scan, ext2_ino_t *ino,
  687.                    struct ext2_inode *inode);
  688. extern errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan,
  689.                            int    group);
  690. extern void ext2fs_set_inode_callback
  691.     (ext2_inode_scan scan,
  692.      errcode_t (*done_group)(ext2_filsys fs,
  693.                  ext2_inode_scan scan,
  694.                  dgrp_t group,
  695.                  void * priv_data),
  696.      void *done_group_data);
  697. extern int ext2fs_inode_scan_flags(ext2_inode_scan scan, int set_flags,
  698.                    int clear_flags);
  699. extern errcode_t ext2fs_read_inode (ext2_filsys fs, ext2_ino_t ino,
  700.                 struct ext2_inode * inode);
  701. extern errcode_t ext2fs_write_inode(ext2_filsys fs, ext2_ino_t ino,
  702.                 struct ext2_inode * inode);
  703. extern errcode_t ext2fs_get_blocks(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
  704. extern errcode_t ext2fs_check_directory(ext2_filsys fs, ext2_ino_t ino);
  705.  
  706. /* icount.c */
  707. extern void ext2fs_free_icount(ext2_icount_t icount);
  708. extern errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags, int size,
  709.                        ext2_icount_t hint, ext2_icount_t *ret);
  710. extern errcode_t ext2fs_create_icount(ext2_filsys fs, int flags, int size,
  711.                       ext2_icount_t *ret);
  712. extern errcode_t ext2fs_icount_fetch(ext2_icount_t icount, ext2_ino_t ino,
  713.                      __u16 *ret);
  714. extern errcode_t ext2fs_icount_increment(ext2_icount_t icount, ext2_ino_t ino,
  715.                      __u16 *ret);
  716. extern errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ext2_ino_t ino,
  717.                      __u16 *ret);
  718. extern errcode_t ext2fs_icount_store(ext2_icount_t icount, ext2_ino_t ino,
  719.                      __u16 count);
  720. extern ext2_ino_t ext2fs_get_icount_size(ext2_icount_t icount);
  721. errcode_t ext2fs_icount_validate(ext2_icount_t icount, FILE *);
  722.  
  723. /* ismounted.c */
  724. extern errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags);
  725. extern errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags,
  726.                       char *mtpt, int mtlen);
  727.  
  728. /* namei.c */
  729. extern errcode_t ext2fs_lookup(ext2_filsys fs, ext2_ino_t dir, const char *name,
  730.              int namelen, char *buf, ext2_ino_t *inode);
  731. extern errcode_t ext2fs_namei(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
  732.             const char *name, ext2_ino_t *inode);
  733. errcode_t ext2fs_namei_follow(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
  734.                   const char *name, ext2_ino_t *inode);
  735. extern errcode_t ext2fs_follow_link(ext2_filsys fs, ext2_ino_t root, ext2_ino_t cwd,
  736.             ext2_ino_t inode, ext2_ino_t *res_inode);
  737.  
  738. /* native.c */
  739. int ext2fs_native_flag(void);
  740.  
  741. /* newdir.c */
  742. extern errcode_t ext2fs_new_dir_block(ext2_filsys fs, ext2_ino_t dir_ino,
  743.                 ext2_ino_t parent_ino, char **block);
  744.  
  745. /* mkdir.c */
  746. extern errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum,
  747.                   const char *name);
  748.  
  749. /* mkjournal.c */
  750. extern errcode_t ext2fs_create_journal_superblock(ext2_filsys fs,
  751.                           __u32 size, int flags,
  752.                           char  **ret_jsb);
  753. extern errcode_t ext2fs_add_journal_device(ext2_filsys fs,
  754.                        ext2_filsys journal_dev);
  755. extern errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t size,
  756.                       int flags);
  757.  
  758. /* openfs.c */
  759. extern errcode_t ext2fs_open(const char *name, int flags, int superblock,
  760.                  int block_size, io_manager manager,
  761.                  ext2_filsys *ret_fs);
  762.  
  763. /* get_pathname.c */
  764. extern errcode_t ext2fs_get_pathname(ext2_filsys fs, ext2_ino_t dir, ext2_ino_t ino,
  765.                    char **name);
  766.  
  767. /* link.c */
  768. errcode_t ext2fs_link(ext2_filsys fs, ext2_ino_t dir, const char *name,
  769.               ext2_ino_t ino, int flags);
  770. errcode_t ext2fs_unlink(ext2_filsys fs, ext2_ino_t dir, const char *name,
  771.             ext2_ino_t ino, int flags);
  772.  
  773. /* read_bb.c */
  774. extern errcode_t ext2fs_read_bb_inode(ext2_filsys fs,
  775.                       ext2_badblocks_list *bb_list);
  776.  
  777. /* read_bb_file.c */
  778. extern errcode_t ext2fs_read_bb_FILE2(ext2_filsys fs, FILE *f, 
  779.                       ext2_badblocks_list *bb_list,
  780.                       void *private,
  781.                       void (*invalid)(ext2_filsys fs,
  782.                               blk_t blk,
  783.                               char *badstr,
  784.                               void *private));
  785. extern errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f, 
  786.                      ext2_badblocks_list *bb_list,
  787.                      void (*invalid)(ext2_filsys fs,
  788.                              blk_t blk));
  789.  
  790. /* rs_bitmap.c */
  791. extern errcode_t ext2fs_resize_generic_bitmap(__u32 new_end,
  792.                           __u32 new_real_end,
  793.                           ext2fs_generic_bitmap bmap);
  794. extern errcode_t ext2fs_resize_inode_bitmap(__u32 new_end, __u32 new_real_end,
  795.                         ext2fs_inode_bitmap bmap);
  796. extern errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
  797.                         ext2fs_block_bitmap bmap);
  798. extern errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src,
  799.                     ext2fs_generic_bitmap *dest);
  800.  
  801. /* swapfs.c */
  802. extern void ext2fs_swap_super(struct ext2_super_block * super);
  803. extern void ext2fs_swap_group_desc(struct ext2_group_desc *gdp);
  804. extern void ext2fs_swap_inode(ext2_filsys fs,struct ext2_inode *t,
  805.                   struct ext2_inode *f, int hostorder);
  806.  
  807. /* valid_blk.c */
  808. extern int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode);
  809.  
  810. /* version.c */
  811. extern int ext2fs_parse_version_string(const char *ver_string);
  812. extern int ext2fs_get_library_version(const char **ver_string,
  813.                       const char **date_string);
  814.  
  815. /* write_bb_file.c */
  816. extern errcode_t ext2fs_write_bb_FILE(ext2_badblocks_list bb_list,
  817.                       unsigned int flags,
  818.                       FILE *f);
  819.  
  820.  
  821. /* inline functions */
  822. extern errcode_t ext2fs_get_mem(unsigned long size, void **ptr);
  823. extern errcode_t ext2fs_free_mem(void **ptr);
  824. extern errcode_t ext2fs_resize_mem(unsigned long old_size,
  825.                    unsigned long size, void **ptr);
  826. extern void ext2fs_mark_super_dirty(ext2_filsys fs);
  827. extern void ext2fs_mark_changed(ext2_filsys fs);
  828. extern int ext2fs_test_changed(ext2_filsys fs);
  829. extern void ext2fs_mark_valid(ext2_filsys fs);
  830. extern void ext2fs_unmark_valid(ext2_filsys fs);
  831. extern int ext2fs_test_valid(ext2_filsys fs);
  832. extern void ext2fs_mark_ib_dirty(ext2_filsys fs);
  833. extern void ext2fs_mark_bb_dirty(ext2_filsys fs);
  834. extern int ext2fs_test_ib_dirty(ext2_filsys fs);
  835. extern int ext2fs_test_bb_dirty(ext2_filsys fs);
  836. extern int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk);
  837. extern int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino);
  838.  
  839. /*
  840.  * The actual inlined functions definitions themselves...
  841.  *
  842.  * If NO_INLINE_FUNCS is defined, then we won't try to do inline
  843.  * functions at all!
  844.  */
  845. #if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS))
  846. #ifdef INCLUDE_INLINE_FUNCS
  847. #define _INLINE_ extern
  848. #else
  849. #ifdef __GNUC__
  850. #define _INLINE_ extern __inline__
  851. #else                /* For Watcom C */
  852. #define _INLINE_ extern inline
  853. #endif
  854. #endif
  855.  
  856. #ifndef EXT2_CUSTOM_MEMORY_ROUTINES
  857. /*
  858.  *  Allocate memory
  859.  */
  860. _INLINE_ errcode_t ext2fs_get_mem(unsigned long size, void **ptr)
  861. {
  862.     *ptr = malloc(size);
  863.     if (!*ptr)
  864.         return EXT2_ET_NO_MEMORY;
  865.     return 0;
  866. }
  867.  
  868. /*
  869.  * Free memory
  870.  */
  871. _INLINE_ errcode_t ext2fs_free_mem(void **ptr)
  872. {
  873.     free(*ptr);
  874.     *ptr = 0;
  875.     return 0;
  876. }
  877.     
  878. /*
  879.  *  Resize memory
  880.  */
  881. _INLINE_ errcode_t ext2fs_resize_mem(unsigned long old_size,
  882.                      unsigned long size, void **ptr)
  883. {
  884.     void *p;
  885.  
  886.     p = realloc(*ptr, size);
  887.     if (!p)
  888.         return EXT2_ET_NO_MEMORY;
  889.     *ptr = p;
  890.     return 0;
  891. }
  892. #endif    /* Custom memory routines */
  893.  
  894. /*
  895.  * Mark a filesystem superblock as dirty
  896.  */
  897. _INLINE_ void ext2fs_mark_super_dirty(ext2_filsys fs)
  898. {
  899.     fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_CHANGED;
  900. }
  901.  
  902. /*
  903.  * Mark a filesystem as changed
  904.  */
  905. _INLINE_ void ext2fs_mark_changed(ext2_filsys fs)
  906. {
  907.     fs->flags |= EXT2_FLAG_CHANGED;
  908. }
  909.  
  910. /*
  911.  * Check to see if a filesystem has changed
  912.  */
  913. _INLINE_ int ext2fs_test_changed(ext2_filsys fs)
  914. {
  915.     return (fs->flags & EXT2_FLAG_CHANGED);
  916. }
  917.  
  918. /*
  919.  * Mark a filesystem as valid
  920.  */
  921. _INLINE_ void ext2fs_mark_valid(ext2_filsys fs)
  922. {
  923.     fs->flags |= EXT2_FLAG_VALID;
  924. }
  925.  
  926. /*
  927.  * Mark a filesystem as NOT valid
  928.  */
  929. _INLINE_ void ext2fs_unmark_valid(ext2_filsys fs)
  930. {
  931.     fs->flags &= ~EXT2_FLAG_VALID;
  932. }
  933.  
  934. /*
  935.  * Check to see if a filesystem is valid
  936.  */
  937. _INLINE_ int ext2fs_test_valid(ext2_filsys fs)
  938. {
  939.     return (fs->flags & EXT2_FLAG_VALID);
  940. }
  941.  
  942. /*
  943.  * Mark the inode bitmap as dirty
  944.  */
  945. _INLINE_ void ext2fs_mark_ib_dirty(ext2_filsys fs)
  946. {
  947.     fs->flags |= EXT2_FLAG_IB_DIRTY | EXT2_FLAG_CHANGED;
  948. }
  949.  
  950. /*
  951.  * Mark the block bitmap as dirty
  952.  */
  953. _INLINE_ void ext2fs_mark_bb_dirty(ext2_filsys fs)
  954. {
  955.     fs->flags |= EXT2_FLAG_BB_DIRTY | EXT2_FLAG_CHANGED;
  956. }
  957.  
  958. /*
  959.  * Check to see if a filesystem's inode bitmap is dirty
  960.  */
  961. _INLINE_ int ext2fs_test_ib_dirty(ext2_filsys fs)
  962. {
  963.     return (fs->flags & EXT2_FLAG_IB_DIRTY);
  964. }
  965.  
  966. /*
  967.  * Check to see if a filesystem's block bitmap is dirty
  968.  */
  969. _INLINE_ int ext2fs_test_bb_dirty(ext2_filsys fs)
  970. {
  971.     return (fs->flags & EXT2_FLAG_BB_DIRTY);
  972. }
  973.  
  974. /*
  975.  * Return the group # of a block
  976.  */
  977. _INLINE_ int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk)
  978. {
  979.     return (blk - fs->super->s_first_data_block) /
  980.         fs->super->s_blocks_per_group;
  981. }
  982.  
  983. /*
  984.  * Return the group # of an inode number
  985.  */
  986. _INLINE_ int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino)
  987. {
  988.     return (ino - 1) / fs->super->s_inodes_per_group;
  989. }
  990. #undef _INLINE_
  991. #endif
  992.  
  993. #ifdef __cplusplus
  994. }
  995. #endif
  996.  
  997. #endif /* _EXT2FS_EXT2FS_H */
  998.